CXXFLAGS  = -O0 -g -Wall -I../libbamp/include -DBOOST_FILESYSTEM_VERSION=3
CFLAGS    = -O0 -g -Wall -std=c99 -pedantic -I../libbamp/include
LDFLAGS   = \
	-L../libbamp/src -lbamp -lboost_thread -lboost_program_options \
	-lboost_iostreams -lboost_filesystem -lboost_system -lboost_regex -ldl

CODEGEN_DIR = ../codegen
CODEGEN = $(CODEGEN_DIR)/codegen.pl -I$(CODEGEN_DIR) -w75

PREFIX=/usr/local

SRC_FILES = \
	 *.cpp pipeline/*.cpp service/*.cpp \
	../libbamp/src/*.c ../libbamp/src/*.cpp
SVC_OBJ   = async_loop.o message_ack.o message_channel.o message_loop.o \
            process_unix.o service.o
PLU_OBJ   = dynamic_lib_unix.o
ALL_OBJ   = \
	$(SVC_OBJ) $(PLU_OBJ) \
	plugin_loader.o control.o control_config.o addon.o console.o \
	playback.o \
	logger.o main.o
OUT       = bamp

GEN_FILES = config.hpp playback_msg_wrap.hpp control_msg_wrap.hpp

CONFIG = \
	-DAPP_NAME=b.AMP \
	-DAPP_VERSION_MAJOR=0 \
	-DAPP_VERSION_MINOR=0 \
	-DAPP_VERSION_BUILD=0

vpath %.c   ../libbamp/src
vpath %.cpp ./service
vpath %.cpp ./pipeline

.PHONY: all install uninstall clean

all: $(OUT)

install: $(OUT)
	cp $(OUT) $(PREFIX)/bin

uninstall:
	rm -f $(PREFIX)/bin/$(OUT)

$(OUT): $(ALL_OBJ)
	$(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS)

%_msg_wrap.hpp: msg_wrap.tmpl.hpp bamp.api
	$(CODEGEN) -D "CLASSNAME=bamp::$*" -i msg_wrap.tmpl.hpp -o $@

config.hpp: config.hpp.tmpl
	$(CODEGEN) $(CONFIG) -i $^ -o $@

clean:
	rm -f $(ALL_OBJ) $(GEN_FILES) $(OUT) .depend

.depend: $(SRC_FILES) $(GEN_FILES)
	$(CXX) $(CXXFLAGS) -MM $^ > .depend

-include .depend
